package com.hrt.thirtyparty.sncode;

import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;

public class SNCodePrintService  implements Printable{

	
	
	private String fileName;
	
	
	
	public SNCodePrintService(String fileName) {
		super();
		this.fileName = fileName;
	}
	
	
	@Override
	public int print(Graphics graphics, PageFormat pf, int pageIndex)
			throws PrinterException {
		 Component c = null;
		   Graphics2D g2 = (Graphics2D) graphics;
		   // 打印起点坐标
		  double x = pf.getImageableX();
		  double y = pf.getImageableY();
		  switch (pageIndex) {
		  case 0: 
		   Image src = Toolkit.getDefaultToolkit().getImage(
				   this.getFileName());


		   g2.drawImage(src, (int) x, (int) y, c);   int img_Height = src.getHeight(c);
		    return PAGE_EXISTS;
		  default:
		   return NO_SUCH_PAGE;
	}

}
	public String getFileName() {
		return fileName;
	}
	public void setFileName(String fileName) {
		this.fileName = fileName;
	}
}
